﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Hydra.Shell.Interfaces;

namespace Hydra.Shell.Utilities
{
    public static class HydraShellUtilities
    {
        private const int LVM_FIRST = 0x1000;
        private const int LVM_SETEXTENDEDLISTVIEWSTYLE = 0x1036;
        private const int LVS_EX_DOUBLEBUFFER = 0x10000;
        private const int TV_FIRST = 0x1100;
        private const int TVM_GETEXTENDEDSTYLE = 0x112d;
        private const int TVM_SETEXTENDEDSTYLE = 0x112c;
        private const int TVS_EX_DOUBLEBUFFER = 4;
        private const int TVS_EX_FADEINOUTEXPANDOS = 0x40;

        //////public static void ApplyListViewThemeStyles(ListView listView)
        //////{
        //////    if (listView == null)
        //////    {
        //////        throw new System.ArgumentNullException("listView");
        //////    }
        //////    System.IntPtr hWnd = listView.get_Handle();
        //////    Microsoft.VisualStudio.NativeMethods.SetWindowTheme(hWnd, "Explorer", null);
        //////    ListView_SetExtendedListViewStyleEx(hWnd, 0x10000, 0x10000);
        //////}

        //////public static void ApplyTreeViewThemeStyles(TreeView treeView)
        //////{
        //////    ApplyTreeViewThemeStyles(treeView, true);
        //////}

        //////public static void ApplyTreeViewThemeStyles(TreeView treeView, bool enableHotTracking)
        //////{
        //////    if (treeView == null)
        //////    {
        //////        throw new System.ArgumentNullException("treeView");
        //////    }
        //////    treeView.set_HotTracking(enableHotTracking);
        //////    treeView.set_ShowLines(false);
        //////    System.IntPtr hWnd = treeView.get_Handle();
        //////    Microsoft.VisualStudio.NativeMethods.SetWindowTheme(hWnd, "Explorer", null);
        //////    int extendedStyle = (int)(TreeView_GetExtendedStyle(hWnd) | 0x44);
        //////    TreeView_SetExtendedStyle(hWnd, extendedStyle, 0);
        //////}

        //////public static int EmptyTaskList(System.IServiceProvider serviceProvider)
        //////{
        //////    if (serviceProvider == null)
        //////    {
        //////        throw new System.ArgumentException("serviceProvider");
        //////    }
        //////    IVsTaskList service = serviceProvider.GetService(typeof(IVsTaskList)) as IVsTaskList;
        //////    if (service == null)
        //////    {
        //////        throw new System.InvalidOperationException();
        //////    }
        //////    int num = 0;
        //////    try
        //////    {
        //////        IVsEnumTaskItems items;
        //////        ErrorHandler.ThrowOnFailure(service.EnumTaskItems(out items));
        //////        if (items == null)
        //////        {
        //////            throw new System.InvalidOperationException();
        //////        }
        //////        uint[] pceltFetched = new uint[1];
        //////        do
        //////        {
        //////            IVsTaskItem[] rgelt = new IVsTaskItem[1];
        //////            num = items.Next(1, rgelt, pceltFetched);
        //////            if (pceltFetched[0] == 1)
        //////            {
        //////                IVsTaskItem2 item = rgelt[0] as IVsTaskItem2;
        //////                if (item != null)
        //////                {
        //////                    int num2;
        //////                    ErrorHandler.ThrowOnFailure(item.CanDelete(out num2));
        //////                    if (num2 == 1)
        //////                    {
        //////                        ErrorHandler.ThrowOnFailure(item.OnDeleteTask());
        //////                    }
        //////                }
        //////            }
        //////        }
        //////        while ((num == 0) && (pceltFetched[0] == 1));
        //////    }
        //////    catch (System.Runtime.InteropServices.COMException exception)
        //////    {
        //////        Trace.WriteLine("Exception : " + exception.get_Message());
        //////        num = exception.get_ErrorCode();
        //////    }
        //////    return num;
        //////}

        //////public static DBGMODE GetDebugMode(System.IServiceProvider serviceProvider)
        //////{
        //////    DBGMODE[] pdbgmode = new DBGMODE[1];
        //////    if (serviceProvider == null)
        //////    {
        //////        throw new System.ArgumentException("serviceProvider");
        //////    }
        //////    IVsDebugger service = serviceProvider.GetService(typeof(IVsDebugger)) as IVsDebugger;
        //////    if (service == null)
        //////    {
        //////        throw new System.InvalidOperationException();
        //////    }
        //////    try
        //////    {
        //////        ErrorHandler.ThrowOnFailure(service.GetMode(pdbgmode));
        //////    }
        //////    catch (System.Runtime.InteropServices.COMException exception)
        //////    {
        //////        Trace.WriteLine("Exception :" + exception.get_Message());
        //////    }
        //////    return pdbgmode[0];
        //////}

        //////public static Font GetEnvironmentFont(System.IServiceProvider provider)
        //////{
        //////    if (provider == null)
        //////    {
        //////        throw new System.ArgumentNullException("provider");
        //////    }
        //////    IUIService service = provider.GetService(typeof(IUIService)) as IUIService;
        //////    if (service == null)
        //////    {
        //////        throw new System.InvalidOperationException();
        //////    }
        //////    return (Font)service.Styles.get_Item("DialogFont");
        //////}

        //////private static System.Collections.Generic.List<IVsWindowFrame> GetFramesForDocument(System.IServiceProvider site, object docData)
        //////{
        //////    IEnumWindowFrames frames;
        //////    System.Collections.Generic.List<IVsWindowFrame> list = new System.Collections.Generic.List<IVsWindowFrame>();
        //////    IVsRunningDocumentTable service = site.GetService(typeof(SVsRunningDocumentTable)) as IVsRunningDocumentTable;
        //////    IVsUIShell shell = site.GetService(typeof(SVsUIShell)) as IVsUIShell;
        //////    if ((shell == null) || (service == null))
        //////    {
        //////        return list;
        //////    }
        //////    ErrorHandler.ThrowOnFailure(shell.GetDocumentWindowEnum(out frames));
        //////    IVsWindowFrame[] rgelt = new IVsWindowFrame[0x10];
        //////    while (true)
        //////    {
        //////        uint num;
        //////        ErrorHandler.ThrowOnFailure(frames.Next((uint)rgelt.Length, rgelt, out num));
        //////        if (num == 0)
        //////        {
        //////            return list;
        //////        }
        //////        for (int i = 0; i < num; i = (int)(i + 1))
        //////        {
        //////            object obj2;
        //////            IVsWindowFrame frame = rgelt[i];
        //////            obj2 = (int)ErrorHandler.ThrowOnFailure(frame.GetProperty(-4004, out obj2));
        //////            if (Microsoft.VisualStudio.NativeMethods.IsSameComObject(obj2, docData))
        //////            {
        //////                list.Add(frame);
        //////            }
        //////        }
        //////    }
        //////}

        //////public static IVsHierarchy GetHierarchy(System.IServiceProvider site, System.Guid projectGuid)
        //////{
        //////    if (site == null)
        //////    {
        //////        throw new System.ArgumentException("site");
        //////    }
        //////    if (projectGuid == System.Guid.Empty)
        //////    {
        //////        throw new System.ArgumentException("projectGuid");
        //////    }
        //////    IVsHierarchy ppHierarchy = null;
        //////    IVsSolution service = site.GetService(typeof(SVsSolution)) as IVsSolution;
        //////    if (service == null)
        //////    {
        //////        throw new System.InvalidOperationException();
        //////    }
        //////    try
        //////    {
        //////        service.GetProjectOfGuid(ref (System.Guid) ref projectGuid, out ppHierarchy);
        //////    }
        //////    catch (System.Runtime.InteropServices.COMException exception)
        //////    {
        //////        Trace.WriteLine("Exception :" + exception.get_Message());
        //////    }
        //////    catch (System.InvalidCastException exception2)
        //////    {
        //////        Trace.WriteLine("Exception :" + exception2.get_Message());
        //////    }
        //////    return ppHierarchy;
        //////}

        //////public static IVsProject3 GetMiscellaneousProject(System.IServiceProvider provider)
        //////{
        //////    IVsProject project;
        //////    if (provider == null)
        //////    {
        //////        throw new System.ArgumentNullException("provider");
        //////    }
        //////    IVsExternalFilesManager service = (IVsExternalFilesManager)provider.GetService(typeof(SVsExternalFilesManager));
        //////    if (service == null)
        //////    {
        //////        return null;
        //////    }
        //////    ErrorHandler.ThrowOnFailure(service.GetExternalFilesProject(out project));
        //////    return (project as IVsProject3);
        //////}

        //////public static IVsProject3 GetMiscellaneousProject(System.IServiceProvider provider, bool create)
        //////{
        //////    if (provider == null)
        //////    {
        //////        throw new System.ArgumentNullException("provider");
        //////    }
        //////    IVsHierarchy ppHierarchy = null;
        //////    System.Guid guid = VSConstants.CLSID_MiscellaneousFilesProject;
        //////    IVsSolution2 service = (IVsSolution2) provider.GetService(typeof(SVsSolution));
        //////    if ((Microsoft.VisualStudio.NativeMethods.Failed(service.GetProjectOfGuid(ref (System.Guid) ref guid, out ppHierarchy)) || (ppHierarchy == null)) && create)
        //////    {
        //////        return GetMiscellaneousProject(provider);
        //////    }
        //////    return (ppHierarchy as IVsProject3);
        //////}

        //////public static IVsOutputWindowPane GetOutputWindowPane(System.IServiceProvider serviceProvider, System.Guid guidPane)
        //////{
        //////    if (serviceProvider == null)
        //////    {
        //////        throw new System.ArgumentException("serviceProvider");
        //////    }
        //////    IVsOutputWindow service = serviceProvider.GetService(typeof(IVsOutputWindow)) as IVsOutputWindow;
        //////    if (service == null)
        //////    {
        //////        throw new System.InvalidOperationException();
        //////    }
        //////    IVsOutputWindowPane ppPane = null;
        //////    try
        //////    {
        //////        ErrorHandler.ThrowOnFailure(service.GetPane(ref (System.Guid) ref guidPane, out ppPane));
        //////    }
        //////    catch (System.Runtime.InteropServices.COMException exception)
        //////    {
        //////        Trace.WriteLine("Exception :" + exception.get_Message());
        //////    }
        //////    return ppPane;
        //////}

        //////public static IVsHierarchy GetProject(System.IServiceProvider site, string moniker)
        //////{
        //////    uint num;
        //////    Microsoft.VisualStudio.OLE.Interop.IServiceProvider provider;
        //////    int num2;
        //////    if (site == null)
        //////    {
        //////        throw new System.ArgumentException("site");
        //////    }
        //////    if (string.IsNullOrEmpty(moniker))
        //////    {
        //////        throw new System.ArgumentException("moniker");
        //////    }
        //////    IVsUIShellOpenDocument service = site.GetService(typeof(SVsUIShellOpenDocument)) as IVsUIShellOpenDocument;
        //////    IVsUIHierarchy ppUIH = null;
        //////    ErrorHandler.ThrowOnFailure(service.IsDocumentInAProject(moniker, out ppUIH, out num, out provider, out num2));
        //////    return ppUIH;
        //////}

        public static void GetRDTDocumentInfo(Hydra.Shell.Interfaces.IServiceProvider site, string documentName, out IHydraHierarchy hierarchy, out uint itemid, out IHydraPersistDocData persistDocData, out uint docCookie)
        {
            hierarchy = null;
            itemid = (uint)uint.MaxValue;
            persistDocData = null;
            docCookie = 0;
            
            if (site == null)
            {
                throw new System.ArgumentException("site");
            }

            if (string.IsNullOrEmpty(documentName))
            {
                throw new System.ArgumentException("documentName");
            }

            IHydraRunningDocumentTable service = site.GetService<IHydraRunningDocumentTable>();

            if (service != null)
            {
                IUnknown zero;

                try
                {
                    service.FindAndLockDocument(Enumerations.HydraRunningDocumentTableFlags.NoLock, documentName, out hierarchy, out itemid, out zero, out docCookie);

                    if (zero != null)
                    {
                        persistDocData = zero as IHydraPersistDocData;
                    }
                }
                finally
                {
                }
            }
        }

        //////public static string GetRunningDocumentContents(System.IServiceProvider site, string path)
        //////{
        //////    if (site == null)
        //////    {
        //////        throw new System.ArgumentException("site");
        //////    }
        //////    if (string.IsNullOrEmpty(path))
        //////    {
        //////        throw new System.ArgumentException("path");
        //////    }
        //////    string pbstrBuf = null;
        //////    IVsRunningDocumentTable service = (IVsRunningDocumentTable)site.GetService(typeof(SVsRunningDocumentTable));
        //////    if (service != null)
        //////    {
        //////        System.IntPtr zero = System.IntPtr.Zero;
        //////        try
        //////        {
        //////            uint num;
        //////            uint num2;
        //////            IVsHierarchy hierarchy;
        //////            ErrorHandler.ThrowOnFailure(service.FindAndLockDocument(0, path, out hierarchy, out num, out zero, out num2));
        //////            if (zero != System.IntPtr.Zero)
        //////            {
        //////                object objectForIUnknown = System.Runtime.InteropServices.Marshal.GetObjectForIUnknown(zero);
        //////                IVsTextLines ppTextBuffer = null;
        //////                if (objectForIUnknown is IVsTextLines)
        //////                {
        //////                    ppTextBuffer = (IVsTextLines)objectForIUnknown;
        //////                }
        //////                else if (objectForIUnknown is IVsTextBufferProvider)
        //////                {
        //////                    IVsTextBufferProvider provider = (IVsTextBufferProvider)objectForIUnknown;
        //////                    if (provider.GetTextBuffer(out ppTextBuffer) != 0)
        //////                    {
        //////                        ppTextBuffer = null;
        //////                    }
        //////                }
        //////                if (ppTextBuffer != null)
        //////                {
        //////                    int num3;
        //////                    int num4;
        //////                    ErrorHandler.ThrowOnFailure(ppTextBuffer.GetLastLineIndex(out num3, out num4));
        //////                    ErrorHandler.ThrowOnFailure(ppTextBuffer.GetLineText(0, 0, num3, num4, out pbstrBuf));
        //////                    ppTextBuffer = null;
        //////                    return pbstrBuf;
        //////                }
        //////            }
        //////        }
        //////        finally
        //////        {
        //////            if (zero != System.IntPtr.Zero)
        //////            {
        //////                System.Runtime.InteropServices.Marshal.Release(zero);
        //////            }
        //////        }
        //////    }
        //////    return null;
        //////}

        //////[System.Obsolete("This method is obsolete. Please use GetTaskItems2 instead.")]
        //////public static System.Collections.Generic.IList<IVsTaskItem2> GetTaskItems(System.IServiceProvider serviceProvider)
        //////{
        //////    System.Collections.Generic.IList<IVsTaskItem2> list = new System.Collections.Generic.List<IVsTaskItem2>();
        //////    foreach (IVsTaskItem item in GetTaskItems2(serviceProvider))
        //////    {
        //////        list.Add(item as IVsTaskItem2);
        //////    }
        //////    return list;
        //////}

        //////public static System.Collections.Generic.IList<IVsTaskItem> GetTaskItems2(System.IServiceProvider serviceProvider)
        //////{
        //////    System.Collections.Generic.IList<IVsTaskItem> list = new System.Collections.Generic.List<IVsTaskItem>();
        //////    if (serviceProvider == null)
        //////    {
        //////        throw new System.ArgumentException("serviceProvider");
        //////    }
        //////    IVsTaskList service = serviceProvider.GetService(typeof(SVsTaskList)) as IVsTaskList;
        //////    if (service == null)
        //////    {
        //////        throw new System.InvalidOperationException();
        //////    }
        //////    try
        //////    {
        //////        IVsEnumTaskItems items;
        //////        ErrorHandler.ThrowOnFailure(service.EnumTaskItems(out items));
        //////        if (items == null)
        //////        {
        //////            return list;
        //////        }
        //////        int num = -2147467259;
        //////        uint[] pceltFetched = new uint[1];
        //////        do
        //////        {
        //////            IVsTaskItem[] rgelt = new IVsTaskItem[1];
        //////            num = items.Next(1, rgelt, pceltFetched);
        //////            if (pceltFetched[0] == 1)
        //////            {
        //////                IVsTaskItem item = rgelt[0];
        //////                list.Add(item);
        //////            }
        //////        }
        //////        while ((num == 0) && (pceltFetched[0] == 1));
        //////    }
        //////    catch (System.Runtime.InteropServices.COMException exception)
        //////    {
        //////        Trace.WriteLine("Exception : " + exception.get_Message());
        //////    }
        //////    return list;
        //////}

        //////public static IVsTextView GetTextView(IVsWindowFrame windowFrame)
        //////{
        //////    object obj2;
        //////    if (windowFrame == null)
        //////    {
        //////        throw new System.ArgumentException("windowFrame");
        //////    }
        //////    ErrorHandler.ThrowOnFailure(windowFrame.GetProperty(-3001, out obj2));
        //////    IVsTextView ppView = obj2 as IVsTextView;
        //////    if (ppView == null)
        //////    {
        //////        IVsCodeWindow window = obj2 as IVsCodeWindow;
        //////        if (window != null)
        //////        {
        //////            ErrorHandler.ThrowOnFailure(window.GetPrimaryView(out ppView));
        //////        }
        //////    }
        //////    return ppView;
        //////}

        //////public static IVsUIHierarchyWindow GetUIHierarchyWindow(System.IServiceProvider serviceProvider, System.Guid guidPersistenceSlot)
        //////{
        //////    if (serviceProvider == null)
        //////    {
        //////        throw new System.ArgumentException("serviceProvider");
        //////    }
        //////    IVsUIShell service = serviceProvider.GetService(typeof(SVsUIShell)) as IVsUIShell;
        //////    if (service == null)
        //////    {
        //////        throw new System.InvalidOperationException();
        //////    }
        //////    object pvar = null;
        //////    IVsWindowFrame ppWindowFrame = null;
        //////    IVsUIHierarchyWindow window = null;
        //////    try
        //////    {
        //////        ErrorHandler.ThrowOnFailure(service.FindToolWindow(0, ref (System.Guid) ref guidPersistenceSlot, out ppWindowFrame));
        //////        ErrorHandler.ThrowOnFailure(ppWindowFrame.GetProperty(-3001, out pvar));
        //////    }
        //////    catch (System.Runtime.InteropServices.COMException exception)
        //////    {
        //////        Trace.WriteLine("Exception :" + exception.get_Message());
        //////    }
        //////    finally
        //////    {
        //////        if (pvar != null)
        //////        {
        //////            IVsWindowPane pane = (IVsWindowPane) pvar;
        //////            window = (IVsUIHierarchyWindow) pane;
        //////        }
        //////    }
        //////    return window;
        //////}

        //////public static Window GetWindowObject(IVsWindowFrame windowFrame)
        //////{
        //////    object obj2;
        //////    if (windowFrame == null)
        //////    {
        //////        throw new System.ArgumentException("windowFrame");
        //////    }
        //////    Window window = null;
        //////    ErrorHandler.ThrowOnFailure(windowFrame.GetProperty(-5003, out obj2));
        //////    if (obj2 is Window)
        //////    {
        //////        window = (Window)obj2;
        //////    }
        //////    return window;
        //////}

        //////public static bool IsDocumentOpen(System.IServiceProvider provider, string fullPath, System.Guid logicalView, out IVsUIHierarchy hierarchy, out uint itemID, out IVsWindowFrame windowFrame)
        //////{
        //////    windowFrame = null;
        //////    itemID = (uint) uint.MaxValue;
        //////    hierarchy = null;
        //////    if (provider == null)
        //////    {
        //////        throw new System.ArgumentException("provider");
        //////    }
        //////    if (string.IsNullOrEmpty(fullPath))
        //////    {
        //////        throw new System.ArgumentException("fullPath");
        //////    }
        //////    IVsUIShellOpenDocument service = provider.GetService(typeof(IVsUIShellOpenDocument)) as IVsUIShellOpenDocument;
        //////    IVsRunningDocumentTable table = provider.GetService(typeof(IVsRunningDocumentTable)) as IVsRunningDocumentTable;
        //////    if ((table != null) && (service != null))
        //////    {
        //////        System.IntPtr zero = System.IntPtr.Zero;
        //////        uint[] pitemidOpen = new uint[1];
        //////        try
        //////        {
        //////            uint num;
        //////            IVsHierarchy hierarchy2;
        //////            int num2;
        //////            ErrorHandler.ThrowOnFailure(table.FindAndLockDocument(0, fullPath, out hierarchy2, out pitemidOpen[0], out zero, out num));
        //////            uint grfIDO = (logicalView == System.Guid.Empty) ? ((uint) 2) : ((uint) 0);
        //////            ErrorHandler.ThrowOnFailure(service.IsDocumentOpen((IVsUIHierarchy) hierarchy2, pitemidOpen[0], fullPath, ref (System.Guid) ref logicalView, grfIDO, out hierarchy, pitemidOpen, out windowFrame, out num2));
        //////            if (windowFrame != null)
        //////            {
        //////                itemID = pitemidOpen[0];
        //////                return (bool) (num2 == 1);
        //////            }
        //////        }
        //////        finally
        //////        {
        //////            if (zero != System.IntPtr.Zero)
        //////            {
        //////                System.Runtime.InteropServices.Marshal.Release(zero);
        //////            }
        //////        }
        //////    }
        //////    return false;
        //////}

        //////public static bool IsInAutomationFunction(System.IServiceProvider serviceProvider)
        //////{
        //////    if (serviceProvider == null)
        //////    {
        //////        throw new System.ArgumentException("serviceProvider");
        //////    }
        //////    IVsExtensibility service = serviceProvider.GetService(typeof(IVsExtensibility)) as IVsExtensibility;
        //////    if (service == null)
        //////    {
        //////        throw new System.InvalidOperationException();
        //////    }
        //////    return (bool)(service.IsInAutomationFunction() != 0);
        //////}

        //////public static bool IsSolutionBuilding(System.IServiceProvider serviceProvider)
        //////{
        //////    if (serviceProvider == null)
        //////    {
        //////        throw new System.ArgumentException("serviceProvider");
        //////    }
        //////    IVsSolutionBuildManager service = serviceProvider.GetService(typeof(IVsSolutionBuildManager)) as IVsSolutionBuildManager;
        //////    if (service == null)
        //////    {
        //////        throw new System.InvalidOperationException();
        //////    }
        //////    int pfBuildManagerBusy = 0;
        //////    ErrorHandler.ThrowOnFailure(service.QueryBuildManagerBusy(out pfBuildManagerBusy));
        //////    return (bool)(pfBuildManagerBusy == 1);
        //////}

        //////public static bool IsVisualStudioInDesignMode(System.IServiceProvider serviceProvider)
        //////{
        //////    if (serviceProvider == null)
        //////    {
        //////        throw new System.ArgumentException("serviceProvider");
        //////    }
        //////    DBGMODE dbgmode = GetDebugMode(serviceProvider) & ~DBGMODE.DBGMODE_EncMask;
        //////    return (bool)(dbgmode == DBGMODE.DBGMODE_Design);
        //////}

        //////public static void LaunchDebugger(System.IServiceProvider serviceProvider, VsDebugTargetInfo info)
        //////{
        //////    if (serviceProvider == null)
        //////    {
        //////        throw new System.ArgumentException("serviceProvider");
        //////    }
        //////    info.cbSize = (uint)System.Runtime.InteropServices.Marshal.SizeOf(info);
        //////    System.IntPtr rgDebugTargetInfo = System.Runtime.InteropServices.Marshal.AllocCoTaskMem((int)info.cbSize);
        //////    System.Runtime.InteropServices.Marshal.StructureToPtr(info, rgDebugTargetInfo, false);
        //////    try
        //////    {
        //////        IVsDebugger service = serviceProvider.GetService(typeof(IVsDebugger)) as IVsDebugger;
        //////        if (service == null)
        //////        {
        //////            throw new System.InvalidOperationException();
        //////        }
        //////        ErrorHandler.ThrowOnFailure(service.LaunchDebugTargets(1, rgDebugTargetInfo));
        //////    }
        //////    catch (System.Runtime.InteropServices.COMException exception)
        //////    {
        //////        Trace.WriteLine("Exception : " + exception.get_Message());
        //////    }
        //////    finally
        //////    {
        //////        if (rgDebugTargetInfo != System.IntPtr.Zero)
        //////        {
        //////            System.Runtime.InteropServices.Marshal.FreeCoTaskMem(rgDebugTargetInfo);
        //////        }
        //////    }
        //////}

        //////private static void ListView_SetExtendedListViewStyleEx(System.IntPtr handle, int mask, int extendedStyle)
        //////{
        //////    Microsoft.VisualStudio.NativeMethods.SendMessage(handle, 0x1036, (System.IntPtr)new System.IntPtr(mask), (System.IntPtr)new System.IntPtr(extendedStyle));
        //////}

        //////public static void OpenAsMiscellaneousFile(System.IServiceProvider provider, string path, string caption, System.Guid editor, string physicalView, System.Guid logicalView)
        //////{
        //////    if (provider == null)
        //////    {
        //////        throw new System.ArgumentException("provider");
        //////    }
        //////    if (string.IsNullOrEmpty(path))
        //////    {
        //////        throw new System.ArgumentException("path");
        //////    }
        //////    IVsProject3 miscellaneousProject = GetMiscellaneousProject(provider);
        //////    VSADDRESULT[] pResult = new VSADDRESULT[1];
        //////    VSADDITEMOPERATION dwAddItemOperation = VSADDITEMOPERATION.VSADDITEMOP_CLONEFILE;
        //////    __VSCREATEEDITORFLAGS __vscreateeditorflags = __VSCREATEEDITORFLAGS.CEF_CLONEFILE;
        //////    ErrorHandler.ThrowOnFailure(miscellaneousProject.AddItemWithSpecific((uint) uint.MaxValue, dwAddItemOperation, caption, 1, new string[] { path }, System.IntPtr.Zero, (uint) __vscreateeditorflags, ref (System.Guid) ref editor, physicalView, ref (System.Guid) ref logicalView, pResult));
        //////    if (pResult[0] != VSADDRESULT.ADDRESULT_Success)
        //////    {
        //////        throw new System.ApplicationException(pResult[0].ToString());
        //////    }
        //////}

        //////public static void OpenDocument(System.IServiceProvider provider, string path)
        //////{
        //////    IVsUIHierarchy hierarchy;
        //////    uint num;
        //////    IVsWindowFrame frame;
        //////    if (provider == null)
        //////    {
        //////        throw new System.ArgumentException("provider");
        //////    }
        //////    if (string.IsNullOrEmpty(path))
        //////    {
        //////        throw new System.ArgumentException("path");
        //////    }
        //////    System.Guid empty = System.Guid.Empty;
        //////    OpenDocument(provider, path, empty, out hierarchy, out num, out frame);
        //////    frame = null;
        //////    hierarchy = null;
        //////}

        //////public static void OpenDocument(System.IServiceProvider provider, string fullPath, System.Guid logicalView, out IVsUIHierarchy hierarchy, out uint itemID, out IVsWindowFrame windowFrame)
        //////{
        //////    windowFrame = null;
        //////    itemID = (uint) uint.MaxValue;
        //////    hierarchy = null;
        //////    if (provider == null)
        //////    {
        //////        throw new System.ArgumentException("provider");
        //////    }
        //////    if (string.IsNullOrEmpty(fullPath))
        //////    {
        //////        throw new System.ArgumentException("fullPath");
        //////    }
        //////    if (!IsDocumentOpen(provider, fullPath, logicalView, out hierarchy, out itemID, out windowFrame))
        //////    {
        //////        IVsUIShellOpenDocument service = provider.GetService(typeof(IVsUIShellOpenDocument)) as IVsUIShellOpenDocument;
        //////        if (service != null)
        //////        {
        //////            Microsoft.VisualStudio.OLE.Interop.IServiceProvider provider2;
        //////            uint num;
        //////            ErrorHandler.ThrowOnFailure(service.OpenDocumentViaProject(fullPath, ref (System.Guid) ref logicalView, out provider2, out hierarchy, out num, out windowFrame));
        //////        }
        //////    }
        //////    if (windowFrame != null)
        //////    {
        //////        ErrorHandler.ThrowOnFailure(windowFrame.Show());
        //////    }
        //////}

        //////public static void OpenDocument(System.IServiceProvider provider, string fullPath, System.Guid logicalView, out IVsUIHierarchy hierarchy, out uint itemID, out IVsWindowFrame windowFrame, out IVsTextView view)
        //////{
        //////    itemID = (uint)uint.MaxValue;
        //////    windowFrame = null;
        //////    hierarchy = null;
        //////    view = null;
        //////    if (provider == null)
        //////    {
        //////        throw new System.ArgumentException("provider");
        //////    }
        //////    if (string.IsNullOrEmpty(fullPath))
        //////    {
        //////        throw new System.ArgumentException("fullPath");
        //////    }
        //////    OpenDocument(provider, fullPath, logicalView, out hierarchy, out itemID, out windowFrame);
        //////    view = GetTextView(windowFrame);
        //////}

        //////public static IVsWindowFrame OpenDocumentWithSpecificEditor(System.IServiceProvider provider, string fullPath, System.Guid editorType, System.Guid logicalView)
        //////{
        //////    IVsUIHierarchy hierarchy;
        //////    uint num;
        //////    IVsWindowFrame frame;
        //////    if (provider == null)
        //////    {
        //////        throw new System.ArgumentException("provider");
        //////    }
        //////    if (string.IsNullOrEmpty(fullPath))
        //////    {
        //////        throw new System.ArgumentException("fullPath");
        //////    }
        //////    OpenDocumentWithSpecificEditor(provider, fullPath, editorType, logicalView, out hierarchy, out num, out frame);
        //////    hierarchy = null;
        //////    return frame;
        //////}

        //////public static void OpenDocumentWithSpecificEditor(System.IServiceProvider provider, string fullPath, System.Guid editorType, System.Guid logicalView, out IVsUIHierarchy hierarchy, out uint itemID, out IVsWindowFrame windowFrame)
        //////{
        //////    windowFrame = null;
        //////    itemID = (uint) uint.MaxValue;
        //////    hierarchy = null;
        //////    if (provider == null)
        //////    {
        //////        throw new System.ArgumentException("provider");
        //////    }
        //////    if (string.IsNullOrEmpty(fullPath))
        //////    {
        //////        throw new System.ArgumentException("fullPath");
        //////    }
        //////    IVsUIShellOpenDocument service = provider.GetService(typeof(IVsUIShellOpenDocument)) as IVsUIShellOpenDocument;
        //////    IVsRunningDocumentTable table = provider.GetService(typeof(IVsRunningDocumentTable)) as IVsRunningDocumentTable;
        //////    string pbstrPhysicalView = null;
        //////    if ((table != null) && (service != null))
        //////    {
        //////        Microsoft.VisualStudio.OLE.Interop.IServiceProvider provider2;
        //////        ErrorHandler.ThrowOnFailure(service.MapLogicalView(ref (System.Guid) ref editorType, ref (System.Guid) ref logicalView, out pbstrPhysicalView));
        //////        System.IntPtr zero = System.IntPtr.Zero;
        //////        try
        //////        {
        //////            uint num;
        //////            IVsHierarchy hierarchy2;
        //////            int num2;
        //////            ErrorHandler.ThrowOnFailure(table.FindAndLockDocument(0, fullPath, out hierarchy2, out itemID, out zero, out num));
        //////            uint grfIDO = 1;
        //////            if (ErrorHandler.Succeeded(service.IsSpecificDocumentViewOpen((IVsUIHierarchy) hierarchy2, itemID, fullPath, ref (System.Guid) ref editorType, pbstrPhysicalView, grfIDO, out hierarchy, out itemID, out windowFrame, out num2)) && (num2 == 1))
        //////            {
        //////                return;
        //////            }
        //////        }
        //////        finally
        //////        {
        //////            if (zero != System.IntPtr.Zero)
        //////            {
        //////                System.Runtime.InteropServices.Marshal.Release(zero);
        //////            }
        //////        }
        //////        uint grfEditorFlags = 3;
        //////        ErrorHandler.ThrowOnFailure(service.OpenDocumentViaProjectWithSpecific(fullPath, grfEditorFlags, ref (System.Guid) ref editorType, pbstrPhysicalView, ref (System.Guid) ref logicalView, out provider2, out hierarchy, out itemID, out windowFrame));
        //////        if (windowFrame != null)
        //////        {
        //////            ErrorHandler.ThrowOnFailure(windowFrame.Show());
        //////        }
        //////        provider2 = null;
        //////    }
        //////}

        //////public static bool PromptYesNo(string message, string title, OLEMSGICON icon, IVsUIShell uiShell)
        //////{
        //////    System.Guid empty = System.Guid.Empty;
        //////    int pnResult = 0;
        //////    ErrorHandler.ThrowOnFailure(uiShell.ShowMessageBox(0, ref (System.Guid) ref empty, title, message, null, 0, OLEMSGBUTTON.OLEMSGBUTTON_YESNO, OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_SECOND, icon, 0, out pnResult));
        //////    return (bool) (pnResult == 6);
        //////}

        //////public static void RenameDocument(System.IServiceProvider site, string oldName, string newName)
        //////{
        //////    if (site == null)
        //////    {
        //////        throw new System.ArgumentException("site");
        //////    }
        //////    if (string.IsNullOrEmpty(oldName))
        //////    {
        //////        throw new System.ArgumentException("oldName");
        //////    }
        //////    if (string.IsNullOrEmpty(newName))
        //////    {
        //////        throw new System.ArgumentException("newName");
        //////    }
        //////    IVsRunningDocumentTable service = site.GetService(typeof(SVsRunningDocumentTable)) as IVsRunningDocumentTable;
        //////    IVsUIShellOpenDocument document = site.GetService(typeof(SVsUIShellOpenDocument)) as IVsUIShellOpenDocument;
        //////    site.GetService(typeof(SVsUIShell));
        //////    if ((service != null) && (document != null))
        //////    {
        //////        IVsHierarchy hierarchy;
        //////        uint num;
        //////        System.IntPtr ptr;
        //////        uint num2;
        //////        ErrorHandler.ThrowOnFailure(service.FindAndLockDocument(0, oldName, out hierarchy, out num, out ptr, out num2));
        //////        if (ptr != System.IntPtr.Zero)
        //////        {
        //////            try
        //////            {
        //////                System.IntPtr ptr3;
        //////                System.IntPtr iUnknownForObject = System.Runtime.InteropServices.Marshal.GetIUnknownForObject(hierarchy);
        //////                System.Guid gUID = typeof(IVsHierarchy).GUID;
        //////                System.Runtime.InteropServices.Marshal.QueryInterface(iUnknownForObject, ref gUID, ref ptr3);
        //////                try
        //////                {
        //////                    ErrorHandler.ThrowOnFailure(service.RenameDocument(oldName, newName, ptr3, num));
        //////                }
        //////                finally
        //////                {
        //////                    System.Runtime.InteropServices.Marshal.Release(ptr3);
        //////                    System.Runtime.InteropServices.Marshal.Release(iUnknownForObject);
        //////                }
        //////                string fileName = System.IO.Path.GetFileName(newName);
        //////                foreach (IVsWindowFrame frame in GetFramesForDocument(site, System.Runtime.InteropServices.Marshal.GetObjectForIUnknown(ptr)))
        //////                {
        //////                    ErrorHandler.ThrowOnFailure(frame.SetProperty(-4001, fileName));
        //////                }
        //////            }
        //////            finally
        //////            {
        //////                System.Runtime.InteropServices.Marshal.Release(ptr);
        //////            }
        //////        }
        //////    }
        //////}

        //////public static void SaveFileIfDirty(IVsTextView view)
        //////{
        //////    IVsTextLines lines;
        //////    int num;
        //////    if (view == null)
        //////    {
        //////        throw new System.ArgumentException("view");
        //////    }
        //////    ErrorHandler.ThrowOnFailure(view.GetBuffer(out lines));
        //////    IVsPersistDocData2 data = (IVsPersistDocData2)lines;
        //////    ErrorHandler.ThrowOnFailure(data.IsDocDataDirty(out num));
        //////    if (num != 0)
        //////    {
        //////        string str;
        //////        int num2;
        //////        int hr = data.SaveDocData(VSSAVEFLAGS.VSSAVE_Save, out str, out num2);
        //////        if (num2 <= 0)
        //////        {
        //////            ErrorHandler.ThrowOnFailure(hr);
        //////        }
        //////        if (!string.IsNullOrEmpty(str))
        //////        {
        //////            string fileName = System.IO.Path.GetFileName(str);
        //////            IVsTextViewEx ex = view as IVsTextViewEx;
        //////            if (ex != null)
        //////            {
        //////                object obj2;
        //////                ex.GetWindowFrame(out obj2);
        //////                IVsWindowFrame frame = obj2 as IVsWindowFrame;
        //////                if (frame != null)
        //////                {
        //////                    ErrorHandler.ThrowOnFailure(frame.SetProperty(-4001, fileName));
        //////                }
        //////            }
        //////        }
        //////    }
        //////    data = null;
        //////    lines = null;
        //////}

        //////public static void SaveFileIfDirty(System.IServiceProvider site, string fullPath)
        //////{
        //////    if (site == null)
        //////    {
        //////        throw new System.ArgumentException("site");
        //////    }
        //////    if (string.IsNullOrEmpty(fullPath))
        //////    {
        //////        throw new System.ArgumentException("fullPath");
        //////    }
        //////    IVsRunningDocumentTable service = (IVsRunningDocumentTable)site.GetService(typeof(SVsRunningDocumentTable));
        //////    if (service != null)
        //////    {
        //////        System.IntPtr ptr;
        //////        uint num;
        //////        uint num2;
        //////        IVsHierarchy hierarchy;
        //////        ErrorHandler.ThrowOnFailure(service.FindAndLockDocument(0, fullPath, out hierarchy, out num, out ptr, out num2));
        //////        if (ptr != System.IntPtr.Zero)
        //////        {
        //////            try
        //////            {
        //////                int num3;
        //////                object objectForIUnknown = System.Runtime.InteropServices.Marshal.GetObjectForIUnknown(ptr);
        //////                IVsPersistDocData2 data = (IVsPersistDocData2)objectForIUnknown;
        //////                ErrorHandler.ThrowOnFailure(data.IsDocDataDirty(out num3));
        //////                if (num3 != 0)
        //////                {
        //////                    string str;
        //////                    int num4;
        //////                    int hr = data.SaveDocData(VSSAVEFLAGS.VSSAVE_Save, out str, out num4);
        //////                    if (num4 <= 0)
        //////                    {
        //////                        ErrorHandler.ThrowOnFailure(hr);
        //////                    }
        //////                    if (!string.IsNullOrEmpty(str))
        //////                    {
        //////                        string fileName = System.IO.Path.GetFileName(str);
        //////                        foreach (IVsWindowFrame frame in GetFramesForDocument(site, objectForIUnknown))
        //////                        {
        //////                            ErrorHandler.ThrowOnFailure(frame.SetProperty(-4001, fileName));
        //////                        }
        //////                    }
        //////                }
        //////            }
        //////            finally
        //////            {
        //////                System.Runtime.InteropServices.Marshal.Release(ptr);
        //////            }
        //////        }
        //////        hierarchy = null;
        //////    }
        //////    service = null;
        //////}

        //////public static int ShowMessageBox(System.IServiceProvider serviceProvider, string message, string title, OLEMSGICON icon, OLEMSGBUTTON msgButton, OLEMSGDEFBUTTON defaultButton)
        //////{
        //////    if (serviceProvider == null)
        //////    {
        //////        throw new System.ArgumentException("serviceProvider");
        //////    }
        //////    IVsUIShell service = serviceProvider.GetService(typeof(IVsUIShell)) as IVsUIShell;
        //////    if (service == null)
        //////    {
        //////        throw new System.InvalidOperationException();
        //////    }
        //////    System.Guid empty = System.Guid.Empty;
        //////    int pnResult = 0;
        //////    ErrorHandler.ThrowOnFailure(service.ShowMessageBox(0, ref (System.Guid) ref empty, title, message, null, 0, msgButton, defaultButton, icon, 0, out pnResult));
        //////    return pnResult;
        //////}

        //////private static int TreeView_GetExtendedStyle(System.IntPtr handle)
        //////{
        //////    return Microsoft.VisualStudio.NativeMethods.SendMessage(handle, 0x112d, System.IntPtr.Zero, System.IntPtr.Zero).ToInt32();
        //////}

        //////private static void TreeView_SetExtendedStyle(System.IntPtr handle, int extendedStyle, int mask)
        //////{
        //////    Microsoft.VisualStudio.NativeMethods.SendMessage(handle, 0x112c, (System.IntPtr)new System.IntPtr(mask), (System.IntPtr)new System.IntPtr(extendedStyle));
        //////}
    }
}
